﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enter.DataProxy.DbConnector;
using Enter.DataProxy.Statistics.Entity;
using Enter.DataCommon;

namespace Enter.DataProxy.Statistics
{
	public class ImgManager:BaseManager
	{
		/// <summary>
		/// 取得一个默认图片样式
		/// </summary>
		/// <returns></returns>
		public string Show_DefImg(int type)
		{
			string sqltxt = "select top 1 imgsrc from [imglist] where state=@type;";
			var db = base.CreateDbWriter();
			ParameterCollection parameters = db.CreateParamCollection(1);
			parameters.Append("type", type);
			string result=db.ExecuteScalar<string>(sqltxt,parameters);
			return result;
		}




		/// <summary>
		/// 显示用户默认图片
		/// </summary>
		/// <param name="userid"></param>
		/// <returns></returns>
		public string Show_UserDefImg(int userid)
		{
			string sqltxt = "select imgdef from userdef where userid=@userid;";

			var db = base.CreateDbWriter();
			ParameterCollection parameters = db.CreateParamCollection(1);
			parameters.Append("userid", userid);

			string result = db.ExecuteScalar<string>(sqltxt, parameters);
			return result;
		}


		/// <summary>
		/// 显示图片列表
		/// </summary>
		/// <param name="pageid"></param>
		/// <param name="pagesize"></param>
		/// <returns></returns>
		public IList<ImglistEntity> Show_PageList(int pageid, int pagesize)
		{
			string sqltxt = "SELECT [id],[title],[imgsrc] FROM  [imglist] where state=0;";
			var db = base.CreateDbReader();
			ParameterCollection parameters = db.CreateParamCollection(3);
			parameters.Append("order", "id");
			parameters.Append("pageid", pageid);
			parameters.Append("pagesize", pagesize);

			var res = db.ExecutePage(sqltxt, parameters);
			IList<ImglistEntity> result = res.ShowEntity<ImglistEntity>();
			return result;
		}



	}
}
